﻿using SMALLERP.DataClass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MSword = Microsoft.Office.Interop.Excel;

namespace XJLSC.RP
{
    public partial class SCReport : Form
    {
        private SqlDataReader sdr1;
        DataBase db = new DataBase();
        public SCReport()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            progressBar1.Visible = true;
            progressBar1.Maximum =8;//设置最大长度值
            progressBar1.Value = 0;//设置当前值
            progressBar1.Step = 1;//设置没次增长多少
            int index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "金工内胆";
            progressBar1.Value += progressBar1.Step;
            String strSql = "SELECT CAST(SUM(TE011) AS REAL) TE011 FROM SFCTE WHERE TE017 LIKE '2%' AND TE017 LIKE '%02' AND TE008='0010' AND UDF08='0010' AND TE001='D410' AND TE023>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TE023<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value =sdr1["TE011"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

          strSql = "SELECT CAST(SUM(TG013) AS REAL) TG013 FROM MOCTG LEFT JOIN MOCTF ON TG001=TF001 AND TG002=TF002 WHERE TG004 LIKE '2%' AND TG004 LIKE '%02' AND TF003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TF003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TG013"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }
            dataGridView1.Rows[index].Cells["BFS"].Value = (Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)).ToString();
            dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value))/ Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value)*100,2)).ToString()+"%";

            index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "金工外壳";
            progressBar1.Value += progressBar1.Step;
            strSql = "SELECT CAST(SUM(TE011) AS REAL) TE011 FROM SFCTE WHERE TE017 LIKE '2%' AND TE017 LIKE '%01' AND TE008='0010' AND UDF08='0010' AND TE001='D410' AND TE023>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TE023<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value = sdr1["TE011"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

            strSql = "SELECT CAST(SUM(TG013) AS REAL) TG013 FROM MOCTG LEFT JOIN MOCTF ON TG001=TF001 AND TG002=TF002 WHERE TG004 LIKE '2%' AND TG004 LIKE '%01' AND TF003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TF003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TG013"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }
            dataGridView1.Rows[index].Cells["BFS"].Value = (Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)).ToString();
            dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)) / Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value)*100,2)).ToString()+"%";


            index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "综合";
            progressBar1.Value += progressBar1.Step;
            strSql = "SELECT CAST(SUM(TE005) AS REAL) TE011 FROM MOCTE LEFT JOIN MOCTC ON TE001=TC001 AND TE002=TC002 WHERE TE004 LIKE '2%' AND TE004 LIKE '%01' AND TC003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TC003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value = sdr1["TE011"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

            strSql = "SELECT CAST(SUM(TG013) AS REAL) TG013 FROM MOCTG LEFT JOIN MOCTF ON TG001=TF001 AND TG002=TF002 WHERE TG004 LIKE '2%' AND TG004 LIKE '%05' AND TF003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TF003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TG013"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }
            dataGridView1.Rows[index].Cells["BFS"].Value = (Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)).ToString();
            dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)) / Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) * 100, 2)).ToString() + "%";

            index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "抛光";
            progressBar1.Value += progressBar1.Step;
            strSql = "SELECT CAST(SUM(TE005) AS REAL) TE011 FROM MOCTE LEFT JOIN MOCTC ON TE001=TC001 AND TE002=TC002 WHERE TE004 LIKE '2%' AND TE004 LIKE '%06' AND TC003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TC003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value = sdr1["TE011"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

            strSql = "SELECT CAST(ISNULL(SUM(TI019),0) AS REAL) TI019 FROM MOCTI LEFT JOIN MOCTH ON TI001=TH001 AND TI002=TH002 WHERE TI004 LIKE '2%' AND TI004 LIKE '%08' AND TH003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TH003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TI019"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }
            dataGridView1.Rows[index].Cells["BFS"].Value = (Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)).ToString();
            dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)) / Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) * 100, 2)).ToString() + "%";


            index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "喷漆/包装";
            progressBar1.Value += progressBar1.Step;
            strSql = "SELECT CAST(SUM(TE005) AS REAL) TE011 FROM MOCTE LEFT JOIN MOCTC ON TE001=TC001 AND TE002=TC002 WHERE TE004 LIKE '2%' AND TE004 LIKE '%08' AND TC003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TC003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value = sdr1["TE011"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

            strSql = "SELECT CAST(SUM(TG013) AS REAL) TG013 FROM MOCTG LEFT JOIN MOCTF ON TG001=TF001 AND TG002=TF002 WHERE TG004 LIKE '8%' AND TF003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TF003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TG013"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }
            dataGridView1.Rows[index].Cells["BFS"].Value = (Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)).ToString();
            dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)) / Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) * 100, 2)).ToString() + "%";

            index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "一次测温";
            progressBar1.Value += progressBar1.Step;
           strSql = "SELECT CAST(ISNULL(SUM(TE011+UDF51+UDF52),0) AS REAL) TRSL,CAST(ISNULL(SUM(TE011),0) AS REAL) TE011,CAST(ISNULL(SUM(UDF51+UDF52),0) AS REAL) BFSL FROM SFCTE WHERE TE009='Z05' AND TE023>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TE023<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value = sdr1["TRSL"].ToString();
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TE011"].ToString();
                    dataGridView1.Rows[index].Cells["BFS"].Value = sdr1["BFSL"].ToString();
                    dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)) / Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) * 100, 2)).ToString() + "%";


                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

            index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "二次测温";
            progressBar1.Value += progressBar1.Step;
            strSql = "SELECT CAST(ISNULL(SUM(TE011+UDF51+UDF52),0) AS REAL) TRSL,CAST(ISNULL(SUM(TE011),0) AS REAL) TE011,CAST(ISNULL(SUM(UDF51+UDF52),0) AS REAL) BFSL FROM SFCTE WHERE TE009='P11' AND TE023>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TE023<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value = sdr1["TRSL"].ToString();
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TE011"].ToString();
                    dataGridView1.Rows[index].Cells["BFS"].Value = sdr1["BFSL"].ToString();
                    dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)) / Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) * 100, 2)).ToString() + "%";


                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

            index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells["BM"].Value = "三次测温";
            progressBar1.Value += progressBar1.Step;
            strSql = "SELECT CAST(ISNULL(SUM(TE011+UDF51+UDF52),0) AS REAL) TRSL,CAST(ISNULL(SUM(TE011),0) AS REAL) TE011,CAST(ISNULL(SUM(UDF51+UDF52),0) AS REAL) BFSL FROM SFCTE WHERE TE009='B11' AND TE023>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker1.Value.ToShortDateString() + "'),112) AND TE023<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker2.Value.ToShortDateString() + "'),112)";
            try
            {
                sdr1 = db.GetDataReader1(strSql);

                while (sdr1.Read())
                {
                    dataGridView1.Rows[index].Cells["TRS"].Value = sdr1["TRSL"].ToString();
                    dataGridView1.Rows[index].Cells["CCS"].Value = sdr1["TE011"].ToString();
                    dataGridView1.Rows[index].Cells["BFS"].Value = sdr1["BFSL"].ToString();
                    dataGridView1.Rows[index].Cells["BFL"].Value = (Math.Round((Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) - Convert.ToDouble(dataGridView1.Rows[index].Cells["CCS"].Value)) / Convert.ToDouble(dataGridView1.Rows[index].Cells["TRS"].Value) * 100, 2)).ToString() + "%";


                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
            finally
            {
                sdr1.Close();
            }

            progressBar1.Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
           String strSql= "SELECT RTRIM(MA001) 供应商,RTRIM(MA002) 供应商简称,CAST((SELECT ISNULL(SUM(TE005),0) TE005 FROM MOCTE LEFT JOIN MOCTC ON TE001 = TC001 AND TE002 = TC002 WHERE TC006 = MA001 AND TC009 = 'Y' AND TE004 LIKE '2%' AND TC003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker3.Value.ToShortDateString() + "'),112)  AND TC003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker4.Value.ToShortDateString() + "'),112)) AS REAL) 投入数,CAST((SELECT ISNULL(SUM(TI019),0) TI019 FROM MOCTI LEFT JOIN MOCTH ON TI001 = TH001 AND TI002 = TH002 WHERE TH005 = MA001 AND TH023 = 'Y' AND TI004 LIKE '2%' AND TH003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker3.Value.ToShortDateString() + "'),112)  AND TH003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker4.Value.ToShortDateString() + "'),112)) AS REAL) 产出数,0 报废数,0.00 报废率 FROM PURMA WHERE EXISTS(SELECT * FROM MOCTI LEFT JOIN MOCTH ON TI001 = TH001 AND TI002 = TH002 WHERE TH005 = MA001 AND TI004 LIKE '2%' AND TI004 LIKE '%06')";
            try
            {
                dataGridView2.DataSource = db.GetDataSet1(strSql, "PURMA").Tables["PURMA"];
                this.dataGridView2.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray;
                this.dataGridView2.AllowUserToAddRows = false;
                for(int i=0;i<=dataGridView2.Rows.Count-1;i++)
                {
                    dataGridView2.Rows[i].Cells["报废数"].Value = (Convert.ToDouble(dataGridView2.Rows[i].Cells["投入数"].Value) - Convert.ToDouble(dataGridView2.Rows[i].Cells["产出数"].Value)).ToString();
                    if (Convert.ToDouble(dataGridView2.Rows[i].Cells["投入数"].Value) > 0)
                    {
                        dataGridView2.Rows[i].Cells["报废率"].Value = (Math.Round((Convert.ToDouble(dataGridView2.Rows[i].Cells["投入数"].Value) - Convert.ToDouble(dataGridView2.Rows[i].Cells["产出数"].Value)) / Convert.ToDouble(dataGridView2.Rows[i].Cells["投入数"].Value) * 100, 6)).ToString() + "%";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            String strSql = "SELECT RTRIM(MA001) 供应商,RTRIM(MA002) 供应商简称,CAST((SELECT ISNULL(SUM(CD008),0) CD008 FROM PURCD LEFT JOIN PURCC ON CD001 = CC001 AND CD002 = CC002 WHERE CC005 = MA001 AND CC009 = 'Y' AND CC003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker5.Value.ToShortDateString() + "'),112)  AND CC003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker6.Value.ToShortDateString() + "'),112)) AS REAL) 到货数,CAST((SELECT ISNULL(SUM(CD018),0) CD018 FROM PURCD LEFT JOIN PURCC ON CD001 = CC001 AND CD002 = CC002 WHERE CC005 = MA001 AND CC009 = 'Y' AND CC003>=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker5.Value.ToShortDateString() + "'),112)  AND CC003<=CONVERT(CHAR(8),DATEADD(DAY,0,'" + dateTimePicker6.Value.ToShortDateString() + "'),112)) AS REAL) 合格数,0 退回数,0.00 不合格率 FROM PURMA WHERE EXISTS(SELECT * FROM PURTH LEFT JOIN PURTG ON TG001 = TH001 AND TG002 = TH002 WHERE TG005 = MA001)";
            try
            {
                dataGridView3.DataSource = db.GetDataSet1(strSql, "PURMA").Tables["PURMA"];
                this.dataGridView3.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray;
                this.dataGridView3.AllowUserToAddRows = false;
                for (int i = 0; i <= dataGridView3.Rows.Count - 1; i++)
                {
                    dataGridView3.Rows[i].Cells["退回数"].Value = (Convert.ToDouble(dataGridView3.Rows[i].Cells["到货数"].Value) - Convert.ToDouble(dataGridView3.Rows[i].Cells["合格数"].Value)).ToString();
                    if (Convert.ToDouble(dataGridView3.Rows[i].Cells["到货数"].Value) > 0)
                    {
                        dataGridView3.Rows[i].Cells["不合格率"].Value = (Math.Round((Convert.ToDouble(dataGridView3.Rows[i].Cells["到货数"].Value) - Convert.ToDouble(dataGridView3.Rows[i].Cells["合格数"].Value)) / Convert.ToDouble(dataGridView3.Rows[i].Cells["到货数"].Value) * 100, 6)).ToString() + "%";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                //throw ex;
            }
        }

        private void dataGridView3_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void dataGridView2_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Execl files (*.xls)|*.xls";
            dlg.FilterIndex = 0;
            dlg.RestoreDirectory = true;
            dlg.CreatePrompt = true;
            dlg.Title = "保存为Excel文件";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string savePath = string.Empty;
                savePath = dlg.FileName;
                //需要添加 Microsoft.Office.Interop.Excel引用 
                Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
                if (null == app)
                {
                    MessageBox.Show("缺少Excel组件！");
                    return;
                }
                app.Visible = false;
                app.UserControl = true;
                Microsoft.Office.Interop.Excel.Workbook workbook = app.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
                // workbook.Sheets.Add();
                try
                {
                    Microsoft.Office.Interop.Excel.Worksheet worksheet = (MSword.Worksheet)workbook.Worksheets[1];
                    // worksheet.Name = "Sheet1";
                    worksheet.Cells.NumberFormatLocal = "@";
                    for (int i = 0; i < dataGridView1.Columns.Count; i++)
                    {
                        worksheet.Cells[1, i + 1] = dataGridView1.Columns[i].Name;
                    }
                    // 保存数据
                    progressBar1.Visible = true;
                    progressBar1.Maximum = dataGridView1.Rows.Count;//设置最大长度值
                    progressBar1.Value = 0;//设置当前值
                    progressBar1.Step = 1;//设置没次增长多少
                    for (int r = 0; r < dataGridView1.Rows.Count; r++)
                    {
                        for (int i = 0; i < dataGridView1.Columns.Count; i++)
                        {
                            worksheet.Cells[r + 2, i + 1] = dataGridView1.Rows[r].Cells[i].Value; ;
                        }
                        progressBar1.Value += progressBar1.Step;
                    }
                    progressBar1.Visible = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                workbook.SaveAs(savePath);
                // 释放资源
                workbook.Close();
                workbook = null;
                app.Quit();
                app = null;
                MessageBox.Show("导出成功", "系统提示");
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Execl files (*.xls)|*.xls";
            dlg.FilterIndex = 0;
            dlg.RestoreDirectory = true;
            dlg.CreatePrompt = true;
            dlg.Title = "保存为Excel文件";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string savePath = string.Empty;
                savePath = dlg.FileName;
                //需要添加 Microsoft.Office.Interop.Excel引用 
                Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
                if (null == app)
                {
                    MessageBox.Show("缺少Excel组件！");
                    return;
                }
                app.Visible = false;
                app.UserControl = true;
                Microsoft.Office.Interop.Excel.Workbook workbook = app.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
                // workbook.Sheets.Add();
                try
                {
                    Microsoft.Office.Interop.Excel.Worksheet worksheet = (MSword.Worksheet)workbook.Worksheets[1];
                    // worksheet.Name = "Sheet1";
                    worksheet.Cells.NumberFormatLocal = "@";
                    for (int i = 0; i < dataGridView3.Columns.Count; i++)
                    {
                        worksheet.Cells[1, i + 1] = dataGridView3.Columns[i].Name;
                    }
                    // 保存数据
                    progressBar1.Visible = true;
                    progressBar1.Maximum = dataGridView3.Rows.Count;//设置最大长度值
                    progressBar1.Value = 0;//设置当前值
                    progressBar1.Step = 1;//设置没次增长多少
                    for (int r = 0; r < dataGridView3.Rows.Count; r++)
                    {
                        for (int i = 0; i < dataGridView3.Columns.Count; i++)
                        {
                            worksheet.Cells[r + 2, i + 1] = dataGridView3.Rows[r].Cells[i].Value; ;
                        }
                        progressBar1.Value += progressBar1.Step;
                    }
                    progressBar1.Visible = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                workbook.SaveAs(savePath);
                // 释放资源
                workbook.Close();
                workbook = null;
                app.Quit();
                app = null;
                MessageBox.Show("导出成功", "系统提示");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Execl files (*.xls)|*.xls";
            dlg.FilterIndex = 0;
            dlg.RestoreDirectory = true;
            dlg.CreatePrompt = true;
            dlg.Title = "保存为Excel文件";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string savePath = string.Empty;
                savePath = dlg.FileName;
                //需要添加 Microsoft.Office.Interop.Excel引用 
                Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
                if (null == app)
                {
                    MessageBox.Show("缺少Excel组件！");
                    return;
                }
                app.Visible = false;
                app.UserControl = true;
                Microsoft.Office.Interop.Excel.Workbook workbook = app.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
                // workbook.Sheets.Add();
                try
                {
                    Microsoft.Office.Interop.Excel.Worksheet worksheet = (MSword.Worksheet)workbook.Worksheets[1];
                    // worksheet.Name = "Sheet1";
                    worksheet.Cells.NumberFormatLocal = "@";
                    for (int i = 0; i < dataGridView2.Columns.Count; i++)
                    {
                        worksheet.Cells[1, i + 1] = dataGridView2.Columns[i].Name;
                    }
                    // 保存数据
                    progressBar1.Visible = true;
                    progressBar1.Maximum = dataGridView2.Rows.Count;//设置最大长度值
                    progressBar1.Value = 0;//设置当前值
                    progressBar1.Step = 1;//设置没次增长多少
                    for (int r = 0; r < dataGridView2.Rows.Count; r++)
                    {
                        for (int i = 0; i < dataGridView2.Columns.Count; i++)
                        {
                            worksheet.Cells[r + 2, i + 1] = dataGridView2.Rows[r].Cells[i].Value; ;
                        }
                        progressBar1.Value += progressBar1.Step;
                    }
                    progressBar1.Visible = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                workbook.SaveAs(savePath);
                // 释放资源
                workbook.Close();
                workbook = null;
                app.Quit();
                app = null;
                MessageBox.Show("导出成功", "系统提示");
            }
        }
    }
}
